package com.atguigu.base;

import com.atguigu.util.CastUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Map;

/**
 * projectName: shf
 *
 * @author: cbc
 * time: 2022/6/7 11:45 周二
 * description:
 */

public abstract class BaseServiceImpl<T> implements BaseService<T> {
    protected abstract BaseMapper<T> getEntityMapper();
    @Override
    public Integer insert(T t) {
        return getEntityMapper().insert(t);
    }
    @Override
    public Integer delete(Serializable id) {
        return getEntityMapper().delete(id);
    }
    @Override
    public Integer update(T t) {
        return getEntityMapper().update(t);
    }
    @Override
    public T getById(Serializable id) {
        return getEntityMapper().getById(id);
    }
    @Override
    public PageInfo<T> findPage(Map<String, Object> filters) {
        int pageNum = CastUtil.castInt(filters.get("pageNum"), 1);
        int pageSize = CastUtil.castInt(filters.get("pageSize"), 10);

        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<T>(getEntityMapper().findPage(filters), 10);
    }

}
